﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using StartupSolution.Assets;
using StartupSolution.Models;

namespace StartupSolution.ViewModel
{
    public class TreemapViewModel : BaseViewModel
    {
        private List<Manufacturer> _manufacturers;
        public List<Manufacturer> Manufacturers
        {
            get { return _manufacturers; }
            set
            {
                _manufacturers = value;
                OnPropertyChanged("Manufacturers");
            }
        }

        public TreemapViewModel()
        {
            XDocument doc = XDocument.Parse(SampleData.Manufacturers);
            Manufacturers =
                (from manufacturer in doc.Element("Manufacturers").Elements("Manufacturer")
                 select new Manufacturer(
                     manufacturer.Attribute("Name").Value,
                     manufacturer.Attribute("Revenue").Value,
                     (
                         from product in manufacturer.Elements("Product")
                         select new InventoryProduct(
                             product.Attribute("Name").Value,
                             product.Attribute("StandardCost").Value,
                             (
                                 from inventoryEntry in product.Elements("InventoryEntry")
                                 select new InventoryEntry(
                                     inventoryEntry.Attribute("Shelf").Value,
                                     inventoryEntry.Attribute("Quantity").Value
                                     )).ToList()
                             )).ToList()
                     )).ToList();
        }
    }
}
